home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: automatic charrs
- Date: Sat, 24 Feb 1996 14:14:05 GMT
- Organization: Netcom
- Message-ID: <312f1cd3.224602571@nntp.ix.netcom.com>
- References: <4glp29$dsh@d2.tufts.edu>
- NNTP-Posting-Host: ix-dc11-01.ix.netcom.com
- X-NETCOM-Date: Sat Feb 24 6:13:32 AM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- rdorich@emerald.tufts.edu (Roberto Dorich) wrote:
-
- > Hello,
- >
- > Could someone enlighten me, and tell me why the following program runs
- > just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
- >
- > #include <stdio.h>
- > char *b() { return "Hello";}
- >
- > main() {
- > char *a=b();
- >
- > a[0]='X';
- > printf("--> %s\n",a);
- > }
- >
- > Esentially, gcc puts out the following assembly code:
- >
- > call b,0
- > nop
- > mov 88,%o1 // %o1 = 'X'
- > stb %o1, [%o0] // a[0] = %o1
- >
- > And cc spits out the following:
- >
- > call b
- > nop
- > mov 88,%l1
- > stb %l1,[%l0+0]
- >
- > (this assembly code has been optimized by me :-/ )
- >
- > Anyway, there isn't really that much difference... but I get a seg fault
- > with gcc. Why?
-
- Modifying literal strings is not supported by the C language.
- Attempting to do so results in undefined behavior.
-
- Apparently gcc puts literal strings in read-only memory and cc does
- not. Either is permissible.
-
-
- Michael M Rubenstein
-